package com.ymatou.iapi.rmq.receiver.testcase;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.rmq.receiver.parameter.PublishBean;
import com.ymatou.iapi.rmq.receiver.service.PublishCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.mongo.JMQMessageBean;
import com.ymttest.database.mongo.JMQMessageCompensateBean;
import com.ymttest.database.mongo.JMQMessageCompensateWapper;
import com.ymttest.database.mongo.JMQMessageDetailBean;
import com.ymttest.database.mongo.JMQMessageDetailWapper;
import com.ymttest.database.mongo.JMQMessageWapper;
import com.ymttest.database.mongo.MQMessageBean;
import com.ymttest.database.mongo.MQMessageCompensateBean;
import com.ymttest.database.mongo.MQMessageCompensateWapper;
import com.ymttest.database.mongo.MQMessageStatusBean;
import com.ymttest.database.mongo.MQMessageStatusWapper;
import com.ymttest.database.mongo.MQMessageWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;


/**
 * 发布消息用例 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_Publish {
	private static PublishBean publishBean;
	private static PublishCall publishCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("发布消息用例");
	}

	@Before
	public void caseUp() {
		publishBean = new PublishBean();
		publishCall = new PublishCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(publishCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_001() {
		Logger.start(true, "发布消息-200发布成功-接收成功");
		try {

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
		//	String body = TestDataManager.randomStr(20);
//			String appName = "xlobo";   
//			String codeName = "createbatchbillinfo";
			String appName = "testdashen";
			String codeName = "publishok";
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.13");
			publishBean.setMsgUniqueId(msguniqueid);
			String body="22222";
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("200", publishCall.getCode(), "验证Success");
			Thread.sleep(10000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.comment("RecvIp : "+messageBean.getRecvIp());
			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);

			int flag = 0;

			while (messageDetailBean == null&&flag<20 || messageDetailBean.getStatus()!=1&&flag<20) {
				Thread.sleep(2000);
				flag++;
				messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);
			}
			
			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("testdashen_publishok_c0", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(1, messageDetailBean.getLastFrom(), "验证数据库lastFrom");
			Logger.verifyEquals(true, messageDetailBean.getLastResp().contains("200, ok"), "验证数据库callNum");
			Logger.verifyEquals(1, messageDetailBean.getStatus(), "验证数据库status:0初始化，1成功，2失败，3补单中");
		
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	@Ignore
	public void Tc_Publish_002() {
		Logger.start(true, "发布消息-201-业务异常");
		try {

			publishCall.setData(publishBean);
			publishCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_Publish_003() {
		Logger.start(true, "发布消息-400-参数异常-invalid appId");
		try {

			String msguniqueid = TestDataManager.getRandomUUID().toString();
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId("testAuto");
			publishBean.setCode("gaoxu");
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("400", publishCall.getCode(), "验证Code");
			Logger.verifyEquals("appId:[testAuto],queueCode:[gaoxu] not exist.", publishCall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_Publish_004() {
		Logger.start(true, "发布消息-400-参数异常-invalid code");
		try {

			String msguniqueid = TestDataManager.getRandomUUID().toString();
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId("test2");
			publishBean.setCode("xud");
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("400", publishCall.getCode(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_Publish_005() {
		Logger.start(true, "发布消息-400-参数异常-appId空");
		try {

			String msguniqueid = TestDataManager.getRandomUUID().toString();
			String body = TestDataManager.randomStr(20);
			// publishBean.setAppId("testAuto");
			publishBean.setCode("gaoxu");
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("400", publishCall.getCode(), "验证Code");
			Logger.verifyEquals("appId not empty", publishCall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_Publish_006() {
		Logger.start(true, "发布消息-400-参数异常-Code空");
		try {

			String msguniqueid = TestDataManager.getRandomUUID().toString();
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId("testAuto");
			// publishBean.setCode("gaoxu");
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("400", publishCall.getCode(), "验证Code");
			Logger.verifyIsContains("code not empty", publishCall.getMsg(), "验证Msg");

			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid("testAuto", "gaoxu", msguniqueid);

			Logger.verifyIsNull(messageBean, "验证数据库未生成相应数据");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_Publish_007() {
		Logger.start(true, "发布消息-400-参数异常-msgUniqueId空");
		try {

			String msguniqueid = TestDataManager.getRandomUUID().toString();
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId("testAuto");
			publishBean.setCode("gaoxu");
			publishBean.setIp("127.0.0.1");
			// publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("400", publishCall.getCode(), "验证Code");
			Logger.verifyIsContains("messageId not empty", publishCall.getMsg(), "验证Msg");

			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid("testAuto", "gaoxu", msguniqueid);
			Logger.verifyIsNull(messageBean, "验证数据库未生成相应数据");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_Publish_008() {
		Logger.start(true, "发布消息-400-参数异常-body空");
		try {

			String msguniqueid = TestDataManager.getRandomUUID().toString();
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId("testdashen");
			publishBean.setCode("publishok");
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			// publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");

			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid("testAuto", "gaoxu", msguniqueid);
			Logger.verifyIsNull(messageBean, "验证数据库未生成相应数据");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_009() {
		Logger.start(true, "发布消息-200发布成功-没配DispatchGroup,不分发,不进补单库");
		try {

			String appName = "test2";
			String codeName = "gaoxu";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);

			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");
			Thread.sleep(1000);

			MQMessageBean messageBean = new MQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);
			Logger.verifyIsNull(messageBean, "验证数据库message未生成");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_010() {
		Logger.start(true, "发布消息-200发布成功-接收失败");
		try {

			String appName = "testdashen";
			String codeName = "publishfail";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.1.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();
			
			Thread.sleep(1000);

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");

			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.comment("RecvIp : "+messageBean.getRecvIp());

			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
				
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);
			
			// 验证补单表
			JMQMessageCompensateBean compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());

			int flag1 = 0;

			while (compensateBean == null || compensateBean.getCompensateNum()==0) {
				Thread.sleep(2000);
				flag1++;
				compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());
			}
			
			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("testdashen_publishfail_c0", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(1, messageDetailBean.getLastFrom(), "验证数据库lastFrom");
			Logger.verifyEquals(true, messageDetailBean.getLastResp().contains("200, fail"), "验证数据库callNum");
			Logger.verifyEquals(3, messageDetailBean.getStatus(), "验证数据库status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			Logger.verifyEquals(compensateBean.getMsgId()+"_"+compensateBean.getConsumerId(), compensateBean.get_id(), "验证数据库_id");
			Logger.verifyEquals(publishBean.getAppId(), compensateBean.getAppId(), "验证数据库AppId");
			Logger.verifyEquals(publishBean.getCode(), compensateBean.getQueueCode(), "验证数据库QueueCode");
			Logger.verifyEquals(messageDetailBean.getConsumerId(), compensateBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(publishBean.getMsgUniqueId(), compensateBean.getBizId(), "验证数据库BizId");
			Logger.verifyEquals("\""+publishBean.getBody()+"\"", compensateBean.getBody(), "验证数据库Body");
			Logger.verifyEquals(1, compensateBean.getSource(), "验证数据库Source:1:分发进补单;2;检测进补单");
			Logger.verifyEquals(0, compensateBean.getStatus(), "验证数据库Status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(true, compensateBean.getCompensateNum()>0, "验证数据库CompensateNum");
			Logger.verifyEquals(2, compensateBean.getLastFrom(), "验证数据库LastFrom");
			Logger.verifyEquals(true, compensateBean.getLastResp().contains("fail"), "验证数据库LastResp");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_011() {
		Logger.start(true, "发布消息-200发布成功-IsRetry=0不补发");
		try {

			String appName = "testbamei";
			String codeName = "bubufa";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishCall.setData(publishBean);
			publishCall.callService();
			
			Thread.sleep(1000);

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			int flag = 0;

			while (messageBean == null) {
				Thread.sleep(200);
				flag++;
				messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);
			}

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.comment("RecvIp : "+messageBean.getRecvIp());

			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			Thread.sleep(5000);
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);

			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("testbamei_bubufa_c1", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(1, messageDetailBean.getLastFrom(), "验证数据库lastFrom");
//			Logger.verifyEquals(true, messageDetailBean.getLastResp().contains("java.net.SocketTimeoutException"), "验证数据库callNum");
			Logger.verifyEquals(2, messageDetailBean.getStatus(), "验证数据库status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(0, messageDetailBean.getCallNum(), "验证数据库CallNum");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证补单表
			JMQMessageCompensateBean compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());
			Logger.verifyEquals(null, compensateBean, "验证数据库_id");		

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	//新版取消秒补的功能，需要秒补的需要改补单站的biz.properties跟订阅者配置
	public void Tc_Publish_012() {
		Logger.start(true, "发布消息-200发布成功-接收失败-秒补");
		try {

			String appName = "testbamei";
			String codeName = "miaosi";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");
			Thread.sleep(1000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			int flag = 0;

			while (messageBean == null) {
				Thread.sleep(200);
				flag++;
				messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);
			}

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			Thread.sleep(5000);
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);

			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("testbamei_miaosi_c0", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(1, messageDetailBean.getLastFrom(), "验证数据库lastFrom");
			Logger.verifyEquals(true, messageDetailBean.getLastResp().contains("200, fail"), "验证数据库callNum");
			Logger.verifyEquals(3, messageDetailBean.getStatus(), "验证数据库status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证补单表
			JMQMessageCompensateBean compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());

			Logger.verifyEquals(compensateBean.getMsgId()+"_"+compensateBean.getConsumerId(), compensateBean.get_id(), "验证数据库_id");
			Logger.verifyEquals(publishBean.getAppId(), compensateBean.getAppId(), "验证数据库AppId");
			Logger.verifyEquals(publishBean.getCode(), compensateBean.getQueueCode(), "验证数据库QueueCode");
			Logger.verifyEquals(messageDetailBean.getConsumerId(), compensateBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(publishBean.getMsgUniqueId(), compensateBean.getBizId(), "验证数据库BizId");
			Logger.verifyEquals("\""+publishBean.getBody()+"\"", compensateBean.getBody(), "验证数据库Body");
			Logger.verifyEquals(0, compensateBean.getSource(), "验证数据库Source:1:分发进补单;2;检测进补单");
			Logger.verifyEquals(0, compensateBean.getStatus(), "验证数据库Status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(true, compensateBean.getCompensateNum()>0, "验证数据库CompensateNum");
			Logger.verifyEquals(2, compensateBean.getLastFrom(), "验证数据库LastFrom");
			Logger.verifyEquals("fail", compensateBean.getLastResp(), "验证数据库LastResp");
			

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_Publish_013() {
		Logger.start(true, "发布消息-200发布成功-接收失败-定时补单");
		try {

			String appName = "testbamei";
			String codeName = "dingshisi";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishCall.setData(publishBean);
			publishCall.callService();
			
			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_014() {
		Logger.start(true, "发布消息-200发布成功-接收成功-EnableLog=False的Code不记录MongoDB日志-JIRACONN-2948");
		try {

			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			String appName = "testbamei";
			String codeName = "nolog";

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");

			Thread.sleep(1000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			if (messageBean == null) {
				Thread.sleep(5000);
				messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);
			}
			Logger.verifyIsNull(messageBean, "验证无数据");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_Publish_015() {
		Logger.start(true, "发布消息-200发布成功-接收失败-EnableLog=False的Code不记录MongoDB补单日志-JIRACONN-2948");
		try {

			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			String appName = "testbamei";
			String codeName = "testlog";

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Thread.sleep(1000);

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");
			Thread.sleep(1000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			int flag = 0;

			while (messageBean == null) {
				Thread.sleep(200);
				flag++;
				messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);
			}

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			Thread.sleep(6000);
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);

			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("testbamei_testlog_c1", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(1, messageDetailBean.getLastFrom(), "验证数据库lastFrom");
			Logger.verifyEquals(true, messageDetailBean.getLastResp().contains("200, fail"), "验证数据库callNum");
			Logger.verifyEquals(3, messageDetailBean.getStatus(), "验证数据库status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证补单表
			JMQMessageCompensateBean compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());

			Logger.verifyEquals(null, compensateBean, "验证数据库未落补单表");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_016() {
		Logger.start(true, "发布消息-200发布成功-返回ok去空格");
		try {

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			String appName = "qukongge_mq";
			String codeName = "qukongge";
			// String codeName = "miaosi";

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Thread.sleep(1000);

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");
			Thread.sleep(1000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			int flag = 0;

			while (messageBean == null) {
				Thread.sleep(200);
				flag++;
				messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);
			}

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.comment("RecvIp : "+messageBean.getRecvIp());

			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			Thread.sleep(5000);
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);

			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("qukongge_mq_qukongge_c0", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(1, messageDetailBean.getStatus(), "验证数据库status");
			Logger.verifyEquals(1, messageDetailBean.getStatus(), "验证数据库callNum");
			Logger.verifyEquals(1, messageDetailBean.getStatus(), "验证数据库lastFrom");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_017() {
		Logger.start(true, "发布消息-200发布成功-接收失败-重试策略未配按照默认的补单");
		try {

			String appName = "testbamei";
			String codeName = "youqusi";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");
			Thread.sleep(1000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);
			
			// 验证补单表
			JMQMessageCompensateBean compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());

			int flag = 0;

			while (compensateBean == null||compensateBean.getCompensateNum()==0) {
				Thread.sleep(200);
				flag++;
				compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());
			}
		
			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("testbamei_youqusi_c0", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(1, messageDetailBean.getLastFrom(), "验证数据库lastFrom");
			Logger.verifyEquals(true, messageDetailBean.getLastResp().contains("fail"), "验证数据库callNum");
			Logger.verifyEquals(3, messageDetailBean.getStatus(), "验证数据库status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			Logger.verifyEquals(compensateBean.getMsgId()+"_"+compensateBean.getConsumerId(), compensateBean.get_id(), "验证数据库_id");
			Logger.verifyEquals(publishBean.getAppId(), compensateBean.getAppId(), "验证数据库AppId");
			Logger.verifyEquals(publishBean.getCode(), compensateBean.getQueueCode(), "验证数据库QueueCode");
			Logger.verifyEquals(messageDetailBean.getConsumerId(), compensateBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(publishBean.getMsgUniqueId(), compensateBean.getBizId(), "验证数据库BizId");
			Logger.verifyEquals("\""+publishBean.getBody()+"\"", compensateBean.getBody(), "验证数据库Body");
			Logger.verifyEquals(1, compensateBean.getSource(), "验证数据库Source:1:分发进补单;2;检测进补单");
			Logger.verifyEquals(0, compensateBean.getStatus(), "验证数据库Status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(true, compensateBean.getCompensateNum()>0, "验证数据库CompensateNum");
			Logger.verifyEquals(2, compensateBean.getLastFrom(), "验证数据库LastFrom");
			Logger.verifyEquals(true, compensateBean.getLastResp().contains("fail"), "验证数据库LastResp");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_018() {
		Logger.start(true, "发布消息-200发布成功-接收失败-补单结束后status为2：失败");
		try {

			String appName = "testdashen";
			String codeName = "publish123";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");
			Thread.sleep(1000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证补单表
			JMQMessageCompensateBean compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());

			int flag = 0;

			while (compensateBean == null||compensateBean.getCompensateNum()!=2) {
				Thread.sleep(200);
				flag++;
				compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());
			}
		
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);

			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("testdashen_publish123_c0", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(2, messageDetailBean.getLastFrom(), "验证数据库lastFrom");
			Logger.verifyEquals(true, messageDetailBean.getLastResp().contains("200, fail"), "验证数据库callNum");
			Logger.verifyEquals(2, messageDetailBean.getStatus(), "验证数据库status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			Logger.verifyEquals(compensateBean.getMsgId()+"_"+compensateBean.getConsumerId(), compensateBean.get_id(), "验证数据库_id");
			Logger.verifyEquals(publishBean.getAppId(), compensateBean.getAppId(), "验证数据库AppId");
			Logger.verifyEquals(publishBean.getCode(), compensateBean.getQueueCode(), "验证数据库QueueCode");
			Logger.verifyEquals(messageDetailBean.getConsumerId(), compensateBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(publishBean.getMsgUniqueId(), compensateBean.getBizId(), "验证数据库BizId");
			Logger.verifyEquals("\""+publishBean.getBody()+"\"", compensateBean.getBody(), "验证数据库Body");
			Logger.verifyEquals(1, compensateBean.getSource(), "验证数据库Source:1:分发进补单;2;检测进补单");
			Logger.verifyEquals(2, compensateBean.getStatus(), "验证数据库Status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(2, compensateBean.getCompensateNum(), "验证数据库CompensateNum");
			Logger.verifyEquals(2, compensateBean.getLastFrom(), "验证数据库LastFrom");
			Logger.verifyEquals(true, compensateBean.getLastResp().contains("超出重试次数、失败|上次结果:200, fail"), "验证数据库LastResp");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_019() {
		Logger.start(true, "发布消息-200发布成功-订阅者未启用");
		try {

			String appName = "testdashen";
			String codeName = "nopublish1";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");
			Thread.sleep(1000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			int flag = 0;

			while (messageBean == null) {
				Thread.sleep(200);
				flag++;
				messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);
			}

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);

			Logger.verifyEquals(null, messageDetailBean, "验证数据库");
	
			// 验证补单表
			JMQMessageCompensateBean compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());

			Logger.verifyEquals(null, compensateBean, "验证数据库未进补单");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_020() {
		Logger.start(true, "发布消息-200发布成功-code未启用");
		try {

			String appName = "testdashen";
			String codeName = "nopublish2";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishCall.setData(publishBean);
			publishCall.callService();

			Thread.sleep(1000);

			Logger.verifyEquals("400", publishCall.getCode(), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_Publish_021() {
		Logger.start(true, "发布消息-验证订阅者重试时间");
		try {

			String appName = "testdashen";
			String codeName = "publishfailendTime";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");
			Thread.sleep(65000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			int flag = 0;

			while (messageBean == null) {
				Thread.sleep(200);
				flag++;
				messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);
			}

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			Thread.sleep(90000);
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);

			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("testdashen_publishfailendTime_c0", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(2, messageDetailBean.getLastFrom(), "验证数据库lastFrom");
			Logger.verifyEquals(true, messageDetailBean.getLastResp().contains("200, fail"), "验证数据库callNum");
			Logger.verifyEquals(2, messageDetailBean.getStatus(), "验证数据库status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证补单表
			JMQMessageCompensateBean compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());

			Logger.verifyEquals(compensateBean.getMsgId()+"_"+compensateBean.getConsumerId(), compensateBean.get_id(), "验证数据库_id");
			Logger.verifyEquals(publishBean.getAppId(), compensateBean.getAppId(), "验证数据库AppId");
			Logger.verifyEquals(publishBean.getCode(), compensateBean.getQueueCode(), "验证数据库QueueCode");
			Logger.verifyEquals(messageDetailBean.getConsumerId(), compensateBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(publishBean.getMsgUniqueId(), compensateBean.getBizId(), "验证数据库BizId");
			Logger.verifyEquals("\""+publishBean.getBody()+"\"", compensateBean.getBody(), "验证数据库Body");
			Logger.verifyEquals(1, compensateBean.getSource(), "验证数据库Source:1:分发进补单;2;检测进补单");
			Logger.verifyEquals(2, compensateBean.getStatus(), "验证数据库Status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(2, compensateBean.getCompensateNum(), "验证数据库CompensateNum");
			Logger.verifyEquals(2, compensateBean.getLastFrom(), "验证数据库LastFrom");
			Logger.verifyEquals(true, compensateBean.getLastResp().contains("超出重试时间、失败|上次结果:200, fail"), "验证数据库LastResp");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_Publish_022() {
		Logger.start(true, "发布消息-200发布失败-并发度0当做2");
		try {

			String appName = "testdashen";
			String codeName = "noconcurrence";

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishCall.setData(publishBean);
			publishCall.callService();

			Thread.sleep(1000);

			Logger.verifyEquals("200", publishCall.getCode(), "验证Code");
			Thread.sleep(1000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			int flag = 0;

			while (messageBean == null) {
				Thread.sleep(200);
				flag++;
				messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);
			}

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);

			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("testdashen_noconcurrence_c0", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(0, messageDetailBean.getLastFrom(), "验证数据库lastFrom");
			Logger.verifyEquals(null, messageDetailBean.getLastResp(), "验证数据库callNum");
			Logger.verifyEquals(0, messageDetailBean.getStatus(), "验证数据库status:0初始化，1成功，2失败，3补单中");
			Logger.verifyEquals(0, messageDetailBean.getCallNum(), "验证数据库CallNum");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证补单表
			JMQMessageCompensateBean compensateBean = new JMQMessageCompensateWapper().getCompensateByMid(publishBean.getAppId(),publishBean.getCode(), messageBean.get_id().toString());

			Logger.verifyEquals(null, compensateBean, "验证数据库未进补单");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_Publish_023() {
		Logger.start(true, "发布消息-200发布成功-没有消费者");
		try {

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			String appName = "testdashen";
			String codeName = "noconsumer";
			// String codeName = "miaosi";

			List<MQMessageStatusBean> statusList = new MQMessageStatusWapper().getStatusByMid(appName, msguniqueid);
			int num1 = statusList.size();

			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.1");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Thread.sleep(1000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			// 验证Message表
			Logger.verifyEquals(null, messageBean, "验证数据库");
					
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);
			Logger.verifyEquals(null,messageDetailBean, "验证数据库");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_Publish_024() {
		Logger.start(true, "发布消息-200发布成功-接收成功");
		try {

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			String body = TestDataManager.randomStr(20);
			String appName = "kafkaApp";
			String codeName = "qusi";

			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.13");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("200", publishCall.getCode(), "验证Success");
			Thread.sleep(10000);
			
			// 验证JMQ_V2_Message库
			JMQMessageBean messageBean = new JMQMessageWapper().getMessageByMid(appName, codeName, msguniqueid);

			Date nowTime = new Date();
			Date date = new Date(nowTime.getTime() - 8 * 60 * 60 * 1000);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH");

			// 验证Message表
			Logger.verifyEquals(publishBean.getAppId(), messageBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("\"" + publishBean.getBody() + "\"", messageBean.getBody(), "验证数据库Body");			
			Logger.verifyEquals(publishBean.getIp(), messageBean.getClientIp(), "验证数据库ClientIp");
			Logger.comment("RecvIp : "+messageBean.getRecvIp());
			Logger.verifyEquals(true,messageBean.getRecvIp().contains("14"), "验证数据库RecvIp,dubbo会主备中随机取一台");
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
			// 验证MessageDetail表
			JMQMessageDetailBean messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);

			int flag = 0;

			while (messageDetailBean == null || messageDetailBean.getStatus()!=1) {
				Thread.sleep(2000);
				flag++;
				messageDetailBean = new JMQMessageDetailWapper().getMessageDetailByMid(appName, codeName, msguniqueid);
			}
			
			Logger.verifyEquals(messageBean.get_id(), messageDetailBean.getMsgId(), "验证数据库BusIp");
			Logger.verifyEquals(publishBean.getAppId(), messageDetailBean.getAppId(), "验证数据库Aid");
			Logger.verifyEquals(publishBean.getCode(), messageDetailBean.getQueueCode(), "验证数据库Code");
			Logger.verifyEquals("testdashen_publishok_c0", messageDetailBean.getConsumerId(), "验证数据库consumerId");
			Logger.verifyEquals(1, messageDetailBean.getLastFrom(), "验证数据库lastFrom");
			Logger.verifyEquals(true, messageDetailBean.getLastResp().contains("200, ok"), "验证数据库callNum");
			Logger.verifyEquals(1, messageDetailBean.getStatus(), "验证数据库status:0初始化，1成功，2失败，3补单中");
		
			Logger.verifyEquals(sdf.format(date), messageBean.getCreateTime().toString().subSequence(7, 20), "验证数据库Ctime");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_025() {
		Logger.start(true, "发布消息-限制messageid长度200-JIRACONN-13909");
		try {

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(210);
			String body = TestDataManager.randomStr(20);
//			String appName = "xlobo";   
//			String codeName = "createbatchbillinfo";
			String appName = "testdashen";
			String codeName = "publishok";
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.13");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body);

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("400", publishCall.getCode(), "验证Success");
			Logger.verifyIsContains("length must be between", publishCall.getMsg(), "验证message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Publish_026() {
		Logger.start(true, "发布消息-限制body长度2621440-JIRACONN-13909");
		try {

			// String msguniqueid = TestDataManager.getRandomUUID().toString();
			String msguniqueid = TestDataManager.getRandomNum(10);
			StringBuffer body=new StringBuffer();
			for(int i=0;i<2621448;i++){
				body.append(TestDataManager.getRandomNum(1));
			}
//			String appName = "xlobo";   
//			String codeName = "createbatchbillinfo";
			String appName = "testdashen";
			String codeName = "publishok";
			publishBean.setAppId(appName);
			publishBean.setCode(codeName);
			publishBean.setIp("127.0.0.13");
			publishBean.setMsgUniqueId(msguniqueid);
			publishBean.setBody(body.toString());

			publishCall.setData(publishBean);
			publishCall.callService();

			Logger.verifyEquals("400", publishCall.getCode(), "验证Success");
			Logger.verifyIsContains("length must be between", publishCall.getMsg(), "验证message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}